﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AutoMeasureV2._1
{
    public class zhengze
    {
        /// <summary>
        /// 对信息进行筛选提取数字部分，含小数点
        /// </summary>
        /// <param name="message">信息</param>
        /// <returns>处理后返回int类型数字</returns>
        public static int SearchNumInt(string message)
        {
            string pattern = @"\d+\.?\d*";  //“\d”表示数字 “+” 表示一个或多个，“\.”表示小数点，“？”表示0或1个，“*”表示无或多个
            string messageNum = string.Empty;
            MatchCollection matches = Regex.Matches(message, pattern, RegexOptions.Multiline);
            foreach (Match match in matches)
            {
                messageNum += match;
            }
            int Num = Convert.ToInt16(messageNum);

            return Num;
        }

        /// <summary>
        /// 对信息进行筛选提取数字部分，含小数点
        /// </summary>
        /// <param name="message">信息</param>
        /// <returns>处理后返回string类型数字</returns>
        public static string SearchNumString(string message)
        {
            string pattern = @"\d+\.?\d*";  //“\d”表示数字 “+” 表示一个或多个，“\.”表示小数点，“？”表示0或1个，“*”表示无或多个
            string Num = string.Empty;
            MatchCollection matches = Regex.Matches(message, pattern, RegexOptions.Multiline);
            foreach (Match match in matches)
            {
                Num += match;
            }

            return Num;
        }

        public static Dictionary<int, string> handleMessage(List<string> AList, List<string> BList)
        {
            Dictionary<int, string> handled = new Dictionary<int, string>();
            handled.Clear();
            int count = AList.Count;
            for (int k = 0; k < count; k++)
            {
                string A = SearchNumString(AList[k]);
                int B = SearchNumInt(BList[k]);
                if (A != string.Empty)
                    handled.Add(B, A);
            }

            handled.OrderBy(x => x.Key);
            return handled;
        }

    }
}
